package com.dt.starter;

import com.bstek.uflo.env.EnvironmentProvider;
import com.dt.core.shiro.ShiroKit;
import com.dt.core.shiro.ShiroUser;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.Resource;
import javax.persistence.EntityManagerFactory;


@Component
@EnableTransactionManagement
public class EnvironmentProviderImpl2 implements EnvironmentProvider {


    @Autowired
    private SessionFactory sessionFactory;

    @Autowired
    private EntityManagerFactory entityManagerFactory;



    private PlatformTransactionManager platformTransactionManager;


    public SessionFactory getSessionFactory() {
        return sessionFactory;

    }


    public PlatformTransactionManager getPlatformTransactionManager() {
        return new JpaTransactionManager(entityManagerFactory);


    }




    public String getCategoryId() {
        return null;
    }
    public String getLoginUser() {
//    	//返回当前系统的登录用户
        ShiroUser u = ShiroKit.getUser();
        String user = "anonymous";
        if (u != null) {
            user = u.getId();
        }
        System.out.println("getLoginUser:" + user);
        return user;
    }


}